<?php

/**
 * WeEngine Api System
 *
 * (c) We7Team 2019 <https://www.w7.cc>
 *
 * This is not a free software
 * Using it under the license terms
 * visited https://www.w7.cc for more details
 */

namespace W7\Sdk\VSCode\Tests;

use W7\Sdk\VSCode\Traits\StorageTrait;

/**
 * fs rename file
 */
class TestFileRename extends TestCase {
	use StorageTrait;

	/**
	 * @var string
	 */
	private $content = 'hello123456';
	/**
	 * @var string
	 */
	private $route = '';
	/**
	 * @var string
	 */
	private $txtFile = '/api/rename.txt';
	/**
	 * @var string
	 */
	private $txtFileRename = '/api/rename2.txt';

	protected function setUp(): void {
		parent::setUp(); // TODO: Change the autogenerated stub
		$this->route = route('vs.code.rename');
	}

	/**
	 * test rename file
	 */
	public function testFileRename() {
		$this->storageDeleteFile($this->txtFile);
		$this->storageDeleteFile($this->txtFileRename);

		$this->storagePutContent($this->txtFile, $this->content);
		$this->assertTrue($this->storageIsExists($this->txtFile));
		$content = $this->storageGetContent($this->txtFile);
		$this->assertEquals($content, $this->content);

		$this->putJson($this->route, ['uri' => $this->txtFile, 'newuri' => $this->txtFileRename])->assertOk();
		$this->assertTrue($this->storageIsExists($this->txtFileRename));
		$content = $this->storageGetContent($this->txtFileRename);
		$this->assertEquals($this->content, $content);
		//        ll($this->content, $content);
	}
}
